package com.http;

import java.util.HashMap;

import org.json.JSONArray;

import android.os.AsyncTask;

import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;
import com.util.JsonUtil;

/**
 * 
 * @ClassName:JobCatCountTask
 * @Description:TODO招聘分类统计
 * @author zhuw
 * @date 2013-9-5 下午2:53:33
 */
public class JobCatCountTask extends AsyncTask<Void, Void, ResultMap> {
	public static interface CallBack extends NetWorkCallBack {
		public abstract void procJobCatCount(HashMap<String, String> map);

	}

	CallBack callback;

	public JobCatCountTask(CallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected ResultMap doInBackground(Void... params) {
		ResultMap data = null;
		try {
			ResEntity re = null;

			re = NetConUtil.sendGetRequestEntity(ServerPath.JOB_CATCOUNT_PATH);

			if (re.code == ResEntity.S_OK) {
				data = new ResultMap(CommonData.H_FLAG_SUCCESS, null,
						JsonUtil.parseCatCountMap(new JSONArray(re.jsonStr)));
			} else if (re.code == ResEntity.S_FAILED) {

				data = new ResultMap(CommonData.H_FLAG_ERROR, "code:" + re.code
						+ "    " + re.jsonStr, null);

			} else {
				data = new ResultMap(CommonData.H_FLAG_ERROR, "code:" + re.code
						+ ErrorCode.ERROR_MSG, null);
			}
		} catch (Exception e) {
			data = new ResultMap(CommonData.H_FLAG_ERROR, ErrorCode.ERROR_MSG,
					null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultMap result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.procJobCatCount(result.resultMap);

		} else {
			callback.procError(result.msg);
		}

	}
}
